package cn.gzjp.modules.rice.entity;

import cn.gzjp.common.config.Global;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import org.hibernate.validator.constraints.Length;

import cn.gzjp.common.persistence.DataEntity;
import cn.gzjp.common.utils.excel.annotation.ExcelField;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/**
 * 产品管理Entity
 * @author zengcp
 * @version 2018-11-17
 */
public class RiceProduct extends DataEntity<RiceProduct> {
	
	private static final long serialVersionUID = 1L;
	private String name;		// 名称
	private String pics;		// 产品轮播图
	private String summary;		// 摘要
	private String content;		// 产品详情
	private int saleCount;		// 销量
	private int praiseRate;		// 好评度

	private String pic;
	private String title;//推广

	private List<ProductStyle> styleList;

	
	public RiceProduct() {
		super();
	}

	public RiceProduct(String id){
		super(id);
	}

	@Length(min=0, max=128, message="名称长度必须介于 0 和 128 之间")
	@ExcelField(title="名称", align=2, sort=1)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Length(min=0, max=512, message="产品轮播图长度必须介于 0 和 512 之间")
	@ExcelField(title="产品轮播图", align=2, sort=2)
	public String getPics() {
		return pics;
	}

	public void setPics(String pics) {
		this.pics = pics;
	}
	
	@Length(min=0, max=256, message="摘要长度必须介于 0 和 256 之间")
	@ExcelField(title="摘要", align=2, sort=3)
	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}
	
	@ExcelField(title="产品详情", align=2, sort=4)
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	


	public List<String> getPicList() {
		if(StrUtil.isNotBlank(this.getPics())){
			String pics[] = this.getPics().split("\\|");
			List<String> picsList = Arrays.asList(pics);
			List<String> result = Lists.newArrayList();
			for(String pic:picsList){
				if(StrUtil.isNotBlank(pic)){
					result.add(Global.getConfig("photoUrl")+pic);
				}
			}
			return result;
		}
		return null;
	}


	public int getSaleCount() {
		return saleCount;
	}

	public void setSaleCount(int saleCount) {
		this.saleCount = saleCount;
	}

	public int getPraiseRate() {
		return praiseRate;
	}

	public void setPraiseRate(int praiseRate) {
		this.praiseRate = praiseRate;
	}

	public String getPic() {
		return pic;
	}

	public void setPic(String pic) {
		this.pic = pic;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getPicUrl() {
		if(StrUtil.isNotBlank(this.getPic())){
			return Global.getConfig("photoUrl")+this.getPic();
		}
		return this.getPic();
	}

	public String getContent2(){
		String content = this.getContent().replaceAll("/static/","https://wuliu.bailingtech.cn/static/");
		return content;
	}

	public List<ProductStyle> getStyleList() {
		return styleList;
	}

	public void setStyleList(List<ProductStyle> styleList) {
		this.styleList = styleList;
	}
}